package com.ysj.demo.accompanynetwork.mvp.model;

import android.util.Log;

import com.google.gson.Gson;
import com.ysj.demo.accompanynetwork.ApiServiceUntil;
import com.ysj.demo.accompanynetwork.bean.BaseBean;
import com.ysj.demo.accompanynetwork.bean.RegisterBean;
import com.ysj.demo.accompanynetwork.bean.RestRsp;
import com.ysj.demo.accompanynetwork.bean.VerificationBean;
import com.ysj.demo.accompanynetwork.mvp.common.OnCommonListener;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by 80530 on 2018/8/18.
 */

public class RegisterModel {

    //获取验证码
    public void getVerificationCode(final OnCommonListener commonListener) {
        Call<RestRsp<VerificationBean>> call = ApiServiceUntil.getInstance().getmApi().getVerificationTask();
        call.enqueue(new Callback<RestRsp<VerificationBean>>() {
            @Override
            public void onResponse(Call<RestRsp<VerificationBean>> call, Response<RestRsp<VerificationBean>> response) {
                RestRsp<VerificationBean> body = response.body();
                Log.i("RegisterActivity获取验证码", new Gson().toJson(body));
                commonListener.onSuccessListener(body);
            }

            @Override
            public void onFailure(Call<RestRsp<VerificationBean>> call, Throwable t) {
                Log.i("RegisterActivity", t.toString());
                commonListener.onFailListener(t);
            }
        });
    }

    //注册
    public void register(RegisterBean bean, final OnCommonListener commonListener) {
        Log.i("RegisterActivity", bean.toString());

        Call<BaseBean> registerCall = ApiServiceUntil.getInstance().getmApi().registerTask(bean);

        registerCall.enqueue(new Callback<BaseBean>() {
            @Override
            public void onResponse(Call<BaseBean> call, Response<BaseBean> response) {
                BaseBean body = response.body();
                commonListener.onSuccessListener(body);
                Log.i("RegisterActivity", new Gson().toJson(body));
            }

            @Override
            public void onFailure(Call<BaseBean> call, Throwable t) {
                Log.i("RegisterActivity", t.toString());
                commonListener.onFailListener(t);
            }
        });
    }
}
